package logic_setting_role

import (
	v1 "Sailor/app/Sailor-console-server/api/api_setting_role/v1"
	"Sailor/app/Sailor-console-server/internal/dao"
	"Sailor/app/Sailor-console-server/internal/model/do"
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/google/uuid"
)

func (s *sSettingRole) LogicSettingRoleCreate(ctx context.Context, req *v1.SettingRoleCreateReq) (res *v1.SettingRoleCreateRes, err error) {

	uid, err := uuid.NewV7()
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("创建失败")
	}
	_, err = dao.SysRole.Ctx(ctx).Insert(do.SysRole{
		Uuid:       uid.String(),
		RoleName:   req.RoleName,
		RoleCode:   req.RoleCode,
		RoleNotes:  req.RoleNotes,
		RoleStatus: req.RoleStatus,
		RoleSort:   req.RoleSort,
	})
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("更新失败")
	}

	return &v1.SettingRoleCreateRes{
		Uuid: uid.String(),
	}, nil
}
